package db

import (
	"context"
	"gluenet/internal/glue-datasyncer/db/prom"
	"gluenet/pkg/ops/impl/es"
	"os"
)

var DefaultDB *DB

type DB struct {
	Es   *es.Es
	Prom *prom.Client
}

func InstallDB() {
	esurl := "http://39.101.140.145:30023"
	promurl := "39.101.140.145:30009"

	mode := os.Getenv("MODE")
	if mode == "prod" {
		esurl = os.Getenv("ES_URL")
		promurl = os.Getenv("PROM_URL")
	}

	dbEs, err := es.NewEs(context.Background(), esurl)
	if err != nil {
		panic(err)
	}

	dbProm, err := prom.OpenProm(promurl)

	DefaultDB = &DB{
		Es:   dbEs,
		Prom: dbProm,
	}
}
